package com.test.reggieadmin.model.dish;

import com.test.reggieadmin.base.BaseObserver;
import com.test.reggieadmin.base.BasePresenter;
import com.test.reggieadmin.bean.BaseBean;
import com.test.reggieadmin.bean.CategoryListBean;
import com.test.reggieadmin.bean.DishDetailsBean;

import java.util.Map;

import okhttp3.MultipartBody;

public class AddDishPrensenter extends BasePresenter<AddDishView> {
    public AddDishPrensenter(AddDishView baseView) {
        super(baseView);
    }

    /**
     * 根据条件查询分类数据
     *
     * @param type
     */
    public void categoryList(int type) {
        addDisposable(apiServer.categoryList(type), new BaseObserver<CategoryListBean>() {
            @Override
            public void onSuccess(CategoryListBean bean) {
                baseView.categoryListSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 新增菜品
     *
     * @param map
     */
    public void addDish(Map<String, Object> map) {
        addDisposable(apiServer.addDish(map), new BaseObserver<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                baseView.addDishSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 文件上传
     *
     * @param part
     */
    public void upload(MultipartBody.Part part) {
        addDisposable(apiServer.upload(part), new BaseObserver<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                baseView.uploadSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 根据id查询菜品信息和对应的口味信息
     *
     * @param id
     */
    public void dishDetails(String id) {
        addDisposable(apiServer.dishDetails(id), new BaseObserver<DishDetailsBean>() {
            @Override
            public void onSuccess(DishDetailsBean bean) {
                baseView.dishDetailsSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 修改菜品
     *
     * @param map
     */
    public void updateDish(Map<String, Object> map) {
        addDisposable(apiServer.updateDish(map), new BaseObserver<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                baseView.updateDishSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }
}
